package com.example.demo.model;

import com.example.demo.enums.ResultStatus;
import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private T data;
    private ResultStatus status;
    private String ErrMsg;

    public static <T> Result<T> success(T data){
        Result<T> result=new Result<>();
        result.setCode(200);
        result.setStatus(ResultStatus.SUCCESS);
        result.setData(data);
        result.setErrMsg("");
        return result;
    }

    public static <T> Result<T> fail(String errMsg){
        Result<T> result=new Result<>();
        result.setCode(-1);
        result.setStatus(ResultStatus.FAIL);
        result.setErrMsg(errMsg);
        return result;
    }

    public static <T> Result<T> noLogin(String errMsg){
        Result<T> result=new Result<>();
        result.setCode(-2);
        result.setStatus(ResultStatus.NO_LOGIN);
        result.setErrMsg(errMsg);
        return result;
    }
}
